package com.huawei.esdk.tp.device.aa;

import org.apache.log4j.Logger;
import com.huawei.esdk.platform.commu.itf.ICXFSOAPProtocolAdapter;
import com.huawei.esdk.platform.exception.ProtocolAdapterException;
import com.huawei.esdk.tp.authorize.SessionManager;
import com.huawei.esdk.tp.common.constants.TPConstant;
import com.huawei.esdk.tp.cxf.enumgen.ClientType;
import com.huawei.esdk.tp.southcommu.cxf.gen.LoginRequestResponseSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.LoginRequestSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.SmcErr2South;

public class SMC20V1R3C00AAService extends SMCAAService
{
    private static final Logger LOGGER = Logger.getLogger(SMCAAService.class);

    public SMC20V1R3C00AAService(ICXFSOAPProtocolAdapter cxfSOAPProtocolAdapter)
    {
        super(cxfSOAPProtocolAdapter);
    }
    
    public LoginRequestResponseSouth smcLoginRequest(String userName)
    {
        LoginRequestSouth reqMessage = new LoginRequestSouth();
        
        
        ClientType clientType = ClientType.API;

        SessionManager sessionMgr = SessionManager.getInstance();
        if(sessionMgr.isSDKSessionExists(TPConstant.SMC_LOGIN_CLIENT_TYPE_OA))
        {
            clientType = ClientType.OA;
        }
        
        reqMessage.setClientType(clientType);
        reqMessage.setUserName(userName);
        reqMessage.setVersion(2);
        LoginRequestResponseSouth res = null;
        
        try
        {
            res = sendSoapMessage(LoginRequestResponseSouth.class, reqMessage, "loginRequest");
        }
        catch (InstantiationException e)
        {
            res = null;
            LOGGER.error("", e);
        }
        catch (IllegalAccessException e)
        {
            res = null;
            LOGGER.error("", e);
        }
        catch (ProtocolAdapterException e)
        {
          //res = null; DTS2015011901913 修改
          res = new LoginRequestResponseSouth();
          SmcErr2South err2South = new SmcErr2South();
          err2South.setErrCode(e.getErrorCode());
          res.setLoginRequestResult(err2South);
          LOGGER.error("", e);
        }
        return res;
    }
    

}
